package cz.anime.ppro.logic;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import cz.anime.ppro.model.Fragment;
import cz.anime.ppro.repositories.FragmentRepository;

@Component
public class FragmentComponentImpl implements FragmentComponent {

	@Autowired
	private FragmentRepository fragmentRepository;
	
	@Override
	public List<Fragment> getFragements() {
		return fragmentRepository.findAll();
	}
	
	@Override
	public Fragment getFragment(int id) {
		Fragment fragment = new Fragment();
		fragment = fragmentRepository.findById(id);		
		return fragment;
	}
	
	@Override
	public void save(Fragment fragment) {
		fragmentRepository.saveAndFlush(fragment);
	}
	
	@Override
	public void delete(Fragment fragment) {
		fragmentRepository.delete(fragment);
	}

}
